#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年10月21日

@author: chenyongbing
'''
import sys,os
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]



sys.path.append('../../')
from base.zhimind_datas import myZhimindDatas
from base.retail_datas import myRetailDatas

fr = open('../report/month.flow.txt','w')
fr.write( '\t'.join(['门店','公司','省份','城市','区域','地址','月份','当月到访天数','客流量'])+'\n')
for month_num in range(1,10):
    day = '2015-0%s-01'%(month_num)
    query = 'select day , any_group , visit_cnt , dist_visit_cnt from month_rank_stats'

    datas = myZhimindDatas.get_target_from_rank_stats_by_group( timeType='month', groupType=4, st=day, et=day, targetList=['dist_visit_cnt','avl_days'])
    
    for group , data in datas.items():
        dist_visit_cnt = data['dist_visit_cnt']
        avl_days = data['avl_days']
        groupInfos = myRetailDatas.get_groups_info(groups=[group])
        if int(group) not in groupInfos.keys():continue
        groupInfo = groupInfos[int(group)]
        group_name=groupInfo['name']
        province = groupInfo['province']
        city = groupInfo['city']
        dist = groupInfo['dist']
        address = groupInfo['address']
        comp_name = myRetailDatas.get_comp_name(shop_group=group)
        if comp_name==None:
            comp_name = '-'
        comp_name = comp_name.encode('utf-8')
        fr.write( '\t'.join([group_name,comp_name,province,city,dist,address,str(month_num),str(avl_days),str(dist_visit_cnt)])+'\n')
fr.close()
    
    
    
    